//
//  MCContractMgtTool.m
//  TLYL
//
//  Created by MC on 2017/11/6.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCContractMgtTool.h"
#import "MCMathUnits.h"

@implementation MCContractMgtTool

//小数转成百分数【带%】
+(NSString *)getPercentNumber:(NSString *)decimals{
decimals = [NSString stringWithFormat:@"%@",decimals];
    float f = [decimals floatValue]*100;
    NSString * s = [NSString stringWithFormat:@"%.3f",f];
    s = GetRealSNum(s);
    s = [NSString stringWithFormat:@"%@%%",s];
    return s;
}

//小数转成百分数【不带%】
+(NSString *)getNPercentNumber:(NSString *)decimals{
    decimals = [NSString stringWithFormat:@"%@",decimals];
    float f = [decimals floatValue]*100;
    NSString * s = [NSString stringWithFormat:@"%.3f",f];
    s = GetRealSNum(s);
    return s;
}

//百分数转变成小数
+(NSString *)getDecimalsNumber:(NSString *)percent{
    percent = [percent stringByReplacingOccurrencesOfString:@"%" withString:@""];
    double f = [percent doubleValue]*0.01;
    NSString * s = [NSString stringWithFormat:@"%.5f",f];
    s = [MCContractMgtTool GetRealNumWithStr:s];

    return s;
}
+(NSString *)GetRealNumWithStr:(NSString *)Snum{
    
    
    NSArray * numArr=[Snum componentsSeparatedByString:@"."];
    if (numArr.count<2) {
        return Snum;
    }
    
    NSString * xiaoshu=numArr[1];
    int index=0;
    for (int i=0; i<xiaoshu.length; i++) {
        NSString * c=[xiaoshu substringWithRange:NSMakeRange((xiaoshu.length-1-i),1)];
        if (![c isEqualToString:@"0"]) {
            
            index=(int)xiaoshu.length-i;
            xiaoshu=[xiaoshu substringWithRange:NSMakeRange(0,index)];
            if (xiaoshu.length>5) {
                xiaoshu=[xiaoshu substringToIndex:5];
            }
            return [NSString stringWithFormat:@"%@.%@",numArr[0],xiaoshu];
            
        }
        if (i==(xiaoshu.length-1)) {
            return numArr[0];
        }
    }
    
    return Snum;
    
}




+(NSString*)GetPercentNumber:(NSString *)decimals andStatisticModeCode:(NSString *)Code{
    
    NSString * StatisticModeCode= [NSString stringWithFormat:@"%@",Code];
    /*
         关于 StatisticModeCode 的说明（StatisticModeCode 有两种情况）：
     
         当 StatisticModeCode =3 ，则代表比例显示方式，【我的日结】【下级日结】的展示，前端需乘以100，加%显示。
         当 StatisticModeCode =4 ，则代表跳跃显示方式，【我的日结】【下级日结】的展示，前端需要取值后乘以10000，再做展示，不加%。
    */
    NSString * MyProportion = [NSString stringWithFormat:@"%@",decimals];
    
    
    if ([StatisticModeCode isEqualToString:@"3"]) {
        
        MyProportion=[NSString stringWithFormat:@"%f",[MyProportion floatValue]*100];
        MyProportion=GetRealSNum(MyProportion);
        return [NSString stringWithFormat:@"%@%%",MyProportion];
        
    }else if([StatisticModeCode isEqualToString:@"4"]){
        MyProportion=[NSString stringWithFormat:@"%f",[MyProportion floatValue]*10000];

        return MyProportion;
    }else{
        return MyProportion;
    }
    
}
@end























